#! /bin/bash
user=root
passwd=123456
db_cluster=mlsql_cluster
db_console=mlsql_console


echo "配置mlsql-cluster的数据"
mysql -u$user -p$passwd -e 'show databases;'
mysql -u$user -p$passwd -e  'drop database if not exists mlsql_cluster;'
mysql -u$user -p$passwd -e  'create database if not exists mlsql_cluster;'
mysql -u$user -p$passwd -D$db_cluster < /opt/mlsql-cluster/db.sql
mysql -u$user -p$passwd -e 'show databases;'


echo "配置mlsql-console的数据"

mysql -u$user -p$passwd -e 'show databases;'
mysql -u$user -p$passwd -e  'drop database if not exists mlsql_console;'
mysql -u$user -p$passwd -e  'create database if not exists mlsql_console;'
mysql -u$user -p$passwd -D$db_console < /opt/mlsql-console/db.sql
mysql -u$user -p$passwd -e 'show databases; use mlsql_console; show tables;'

echo "数据库授权mlsql用户"

mysql -u$user -p$passwd -e 'create user mlsql@localhost identified by 'mlsql123';'
mysql -u$user -p$passwd -e 'grant all privileges on mlsql_cluster.* to mlsql@localhost;'
mysql -u$user -p$passwd -e 'grant all privileges on mlsql_console.* to mlsql@localhost;'
